import face_recognition
import cv2
img_path = r"./data/test1.jpeg"
imgs = cv2.imread(img_path, cv2.IMREAD_COLOR)
# 检测人脸位置
face_locations = face_recognition.face_locations(imgs)
face_landmarks_list = face_recognition.face_landmarks(imgs)
#print(face_landmarks_list)
# 根据检测出的人脸位置画框框出人脸
for i in range(len(face_locations)):
    cv2.rectangle(imgs,(face_locations[i][1],face_locations[i][0]),(face_locations[i][3],face_locations[i][2]),color=(0,255,0))
# 显示人脸检测效果
# cv2.imshow("image", imgs)
# cv2.waitKey(0)
# import face_recognition
# image = face_recognition.load_image_file("your_file.jpg")
# face_locations = face_recognition.face_locations(image)    
img1 = face_recognition.load_image_file(r"./data/test1.jpeg")
img2 = face_recognition.load_image_file(r"./data/test2.jpeg")
img3 = face_recognition.load_image_file(r"./data/test3.jpeg")

img1_encoding = face_recognition.face_encodings(img1)[0]
img2_encoding = face_recognition.face_encodings(img2)[0]
img3_encoding = face_recognition.face_encodings(img3)[0]

results = face_recognition.compare_faces([img1_encoding,img2_encoding,img3_encoding], img3_encoding, tolerance=0.3)
face_distances = face_recognition.face_distance([img1_encoding,img2_encoding,img3_encoding], img3_encoding)

print(results)
print(face_distances)

